package org.StarTest;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.facebook.api.*;

/**
 * Servlet implementation class AbstractFacebookServlet
 */
public class AbstractFacebookServlet 
  extends javax.servlet.http.HttpServlet 
  implements javax.servlet.Servlet
{
	protected static final String FB_APP_URL = 
		"http://apps.facebook.com/";
	
	protected static final String FB_APP_ADD_URL =
		"http://www.facebook.com/add.php?api_key=";
		
	protected static final String FB_API_KEY =
		"556b81944a332a218cfb68b12b0d0ca8";
	
	protected static final String FB_SECRET_KEY = 
		"7e071486f299d072e76930ff8b50d29e";
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AbstractFacebookServlet() {
        super();
    }

	/*
    * This method is used by all of the application's servlets
    * (or  web framework actions) to authenticate the app with
    * Facebook.
    */
   protected FacebookRestClient getAuthenticatedFacebookClient(
		  HttpServletRequest request, HttpServletResponse response)
   {
      Facebook fb = new Facebook(request, response,FB_API_KEY, FB_SECRET_KEY);

	  String next = request.getServletPath().substring(1);

      if (fb.requireLogin(next)) return null;

      return fb.getFacebookRestClient();
   }	
}
